<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>提取图片中文字信息</title>
    <script src="https://cdn.jsdelivr.net/npm/tesseract.js@5.0.3/dist/tesseract.min.js"></script>
</head>
<body>
<input type="file" id="uploader" multiple>
<script type="module">

    // This is a basic example more efficient than "basic.html".
    // In this example we create a worker once, and this worker is re-used
    // every time the user uploads a new file.
    const worker = await Tesseract.createWorker("chi_sim+eng", 1, {
        // corePath: '../../node_modules/tesseract.js-core',
        workerPath: "https://cdn.jsdelivr.net/npm/tesseract.js@5.0.3/dist/worker.min.js",
        logger: function (m) {
            console.log(m);
        }
    });

    const recognize = async function (evt) {
        const files = evt.target.files;

        for (let i = 0; i < files.length; i++) {
            const ret = await worker.recognize(files[i]);
            console.log(ret.data.text);
        }
    }
    const elm = document.getElementById('uploader');
    elm.addEventListener('change', recognize);
</script>

</body>
</html>